package com.yanyilu.qiubite.jpa;

import com.yanyilu.qiubite.entity.Storyline;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface StorylineJpa extends JpaRepository<Storyline,Integer> {

    @Modifying
    @Query(value = "delete from storyline where part_id in :partIds",nativeQuery = true)
    void deleteByPartIds(@Param("partIds")List<Integer> partIds);

    @Modifying
    @Query(value = "delete from storyline where part_id = :partId",nativeQuery = true)
    void deleteByPartId(@Param("partId")Integer partId);

    @Modifying
    @Query(value = "delete from storyline where line_id = :lineId and spot_id = :spotId",nativeQuery = true)
    void deleteByLinedAndSpotId(@Param("lineId") Integer lineId, @Param("spotId")Integer spotId);

    @Query(value = "select * from storyline where part_id = :partId",nativeQuery = true )
    Page<Storyline> findByPartId(@Param("partId")Integer partId, Pageable pageable);

    @Query(value = "select * from storyline where part_id = :partId",nativeQuery = true )
    Page<Storyline> findByPartIdAndSpotId(@Param("partId")Integer partId, Pageable pageable);

    @Query(value = "select * from storyline where part_id = :partId",nativeQuery = true )
    List<Storyline> findListByPartId(@Param("partId")Integer partId);

    @Query(value = "select line_answer from storyline where line_id = :lineId",nativeQuery = true)
    String findLineAnswerById(@Param("lineId")Integer lineId);
}
